Dart BigInt operator |
Syntax & Examples
BigInt.operator | operator
The `operator |` in Dart performs a bitwise OR operation between two BigInt objects.
Syntax of BigInt.operator |
The syntax of BigInt.operator | operator is:
operator |(BigInt other) → BigIntThis operator | operator of BigInt bit-wise or operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt object to perform the bitwise OR operation with |
✐ Examples
1 Perform bit-wise OR operation
In this example,
- We create two BigInt objects,
num1andnum2, initialized with different values. - We use the
|operator to perform a bit-wise OR operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(7);
BigInt result = num1 | num2;
print('Bit-wise OR of num1 and num2: $result');
}Output
Bit-wise OR of num1 and num2: 15
2 Perform bit-wise OR operation with hexadecimal numbers
In this example,
- We create two BigInt objects,
num1andnum2, initialized with hexadecimal values. - We use the
|operator to perform a bit-wise OR operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(0x55);
BigInt num2 = BigInt.from(0xAA);
BigInt result = num1 | num2;
print('Bit-wise OR of num1 and num2: $result');
}Output
Bit-wise OR of num1 and num2: 255
3 Perform bit-wise OR operation with binary numbers
In this example,
- We create two BigInt objects,
num1andnum2, initialized with binary values. - We use the
|operator to perform a bit-wise OR operation betweennum1andnum2. - We print the result of the operation to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(0b1100);
BigInt num2 = BigInt.from(0b1010);
BigInt result = num1 | num2;
print('Bit-wise OR of num1 and num2: $result');
}Output
Bit-wise OR of num1 and num2: 14
Summary
In this Dart tutorial, we learned about operator | operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.